package com.acme.bankapp.service.bank;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.AccountComparator;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.Client;

public class BankReport {
	public static void getNbOfCustomers(Bank bank) {
		System.out.println("Number of clients in bank are: "
				+ bank.getClients().size() + "\n");
	}

	public static void getNbOfAccounts(Bank bank) {
		int n = 0;
		for (Client cl : bank.getClients()) {
			n += cl.getAccounts().size();
		}
		System.out.println("Number of accounts in bank are: " + n);
		System.out.println("\n");
	}

	public static void getAccountsSortedBySum(Bank bank) {
		ArrayList<Account> al = new ArrayList<>();
		for (Client cl : bank.getClients()) {
			for (Account ac : cl.getAccounts()) {
				al.add(ac);
			}
		}
		Collections.sort(al, new AccountComparator());
		System.out.println("Accounts sorted by sum:");
		for (Account ac : al) {
			System.out.println(ac.toString());
		}
		System.out.println("\n");
	}

	public static void getBankCredit(Bank bank) {
		int n = 0;
		for (Client cl : bank.getClients()) {
			for (Account ac : cl.getAccounts()) {
				n += ac.getCredit();
			}
		}
		System.out.println("Overall bank credit is: " + n + "\n");
	}

	public static void getCustomerAccount(Bank bank) {
		Map<Client, Set<Account>> map = new HashMap<Client, Set<Account>>();
		for (Client cl : bank.getClients()) {
			map.put(cl, cl.getAccounts());
		}
		System.out.println("Bank as map");
		System.out.println(map);
	}
}
